package com.polaris.live.utils.sensor.module

import androidx.appcompat.app.AppCompatActivity
import com.polaris.live.common.util.ToastGravity
import com.polaris.live.im.db.database.AppDatabase
import com.polaris.live.im.manager.ImSessionManager
import com.polaris.live.utils.sensor.base.DialogModule
import com.polaris.live.utils.sensor.base.FunctionModule
import com.polaris.live.utils.sensor.base.IModule
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kotlin.system.exitProcess

/**
 * FunctionToolsModule
 *
 * @author Created by lucas on 2024/5/30 02:06
 * @since 1.0.0
 */
class FunctionToolsModule(
    context: AppCompatActivity
) : DialogModule(context) {

    override val title: String
        get() = "Function Tools"

    override fun createModules(): Array<IModule> = arrayOf(
        FunctionModule(mContext, "Reset Session UnreadCount", {
            ImSessionManager.triggerSessionUnreadCountCalculation()
        }),
        FunctionModule(mContext, "Delete All Message", {
            ImSessionManager.launchSession {
                AppDatabase.instance.sessionListDao().truncateTable()
                AppDatabase.instance.messageDao().truncateTable()

                withContext(Dispatchers.Main) {
                    ToastGravity.showGravity("Delete All Message Success")
                }

                exitProcess(0)
            }
        })
    )
}